package com.itheima.redbaby.engine.impl;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.itheima.redbaby.ContantValue;
import com.itheima.redbaby.bean.Category;
import com.itheima.redbaby.bean.Topic;
import com.itheima.redbaby.engine.BaseEngine;
import com.itheima.redbaby.engine.CategoryEngine;
import com.itheima.redbaby.engine.TopicEngine;

public class TopicEngineImpl extends BaseEngine implements TopicEngine {

	@Override
	public List<String> getTopicId() {
		List<String> listId = new ArrayList<String>();
		// 获取到json
		JSONObject json = getJson(TYPE_GET, ContantValue.REDBOY_TOPIC_URIL,
				null);
		// 获得json中的bean 对象

		List<Topic> topicList = JSONObject.parseArray(json.getString("topic"),
				Topic.class);
		for (Topic topic : topicList) {
			String topicId = topic.getId();
			listId.add(topicId);
		}
		return listId;
	}

	@Override
	public List<String> getTopicName() {
		List<String> topicName = new ArrayList<String>();
		// 获取到json
		JSONObject json = getJson(TYPE_GET, ContantValue.REDBOY_TOPIC_URIL,
				null);
		// 获得json中的bean 对象

		List<Topic> topicList = JSONObject.parseArray(json.getString("topic"),
				Topic.class);
		for (Topic topic : topicList) {
			String name = topic.getName();
			topicName.add(name);
		}
		return topicName;
	}

	@Override
	public List<Topic> getTopic() {

		// 获取到json
		JSONObject json = getJson(TYPE_GET, ContantValue.REDBOY_TOPIC_URIL,null);
		// 获得json中的bean 对象
		List<Topic> topic = JSONObject.parseArray(json.getString("topic"),
				Topic.class);

		return topic;

	}

}
